<?php

namespace App\Model;

use App\User;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Business extends Model
{
    use HasFactory;

    public $table = 'business';

    public $guarded = [];

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function agent(){
        return $this->belongsTo(Agent::class);
    }

    public function devices(){
        return $this->hasMany(Device::class,'business_id','id');
    }
    public function house()
    {
        return $this->hasMany(House::class);
    }

    public function getHouseCountAttribute()
    {
        return $this->house()->count();
    }

    public function conf()
    {
        return $this->hasOne(BusinessConf::class);
    }

    public function order()
    {
        return $this->hasMany(Order::class);
    }
}
